<template>
  <div>
    <span>{{ code }}</span>
    <i
      class="el-icon-document copy"
      title="点击复制"
      @click="copyActiveCode($event, code)"
    />
  </div>
</template>

<script>
import Clipboard from "clipboard";
export default {
  data() {
    return {
      code: "11",
    };
  },
  methods: {
    copyActiveCode(e, text) {
        let clipboard = new Clipboard(e.target,{text:() => text})
    //   let clipboard = new Clipboard(".copy", {text:() => text});

      clipboard.on("success", (e) => {
        this.$message({
          type: "success",
          message: "复制成功",
        });
        e.clearSelection();
      });

      clipboard.on("error", (e) => {
        this.$message({
          type: "warning",
          message: "未复制成功，请手动复制",
        });
      });
    },
  },
};
</script>

<style lang="scss" scoped>
</style>